import request from '@/config/axios'
import type { Dayjs } from 'dayjs';

/** 预约信息 */
export interface Appointment {
          id: number; // 预约ID
          studentId?: number; // 学生ID
          commodityId?: number; // 商品ID
          venueId: number; // 场地ID
          appointmentDate: string | Dayjs; // 预约日期
          timeRange: number; // 预约时间段(tr_course_time字典)
          appointmentStatus: number; // 预约状态
  }

// 预约 API
export const AppointmentApi = {
  // 查询预约分页
  getAppointmentPage: async (params: any) => {
    return await request.get({ url: `/train/appointment/page`, params })
  },

  // 查询预约详情
  getAppointment: async (id: number) => {
    return await request.get({ url: `/train/appointment/get?id=` + id })
  },

  // 新增预约
  createAppointment: async (data: Appointment) => {
    return await request.post({ url: `/train/appointment/create`, data })
  },

  // 修改预约
  updateAppointment: async (data: Appointment) => {
    return await request.put({ url: `/train/appointment/update`, data })
  },

  // 删除预约
  deleteAppointment: async (id: number) => {
    return await request.delete({ url: `/train/appointment/delete?id=` + id })
  },

  /** 批量删除预约 */
  deleteAppointmentList: async (ids: number[]) => {
    return await request.delete({ url: `/train/appointment/delete-list?ids=${ids.join(',')}` })
  },

  // 导出预约 Excel
  exportAppointment: async (params) => {
    return await request.download({ url: `/train/appointment/export-excel`, params })
  }
}